//
//  MYGAddFriendHeaderView.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/25.
//

import UIKit

class MYGAddFriendHeaderView: UIView {

       override init(frame: CGRect) {
        super.init(frame: frame)
        configUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        backgroundColor = .rgba(250, 250, 250, 1)
        
        addSubviews([scanView,weiChatView,findView])
        
        scanView.snp.makeConstraints { make in
            make.left.top.right.equalToSuperview()
            make.height.equalTo(58)
        }
        weiChatView.snp.makeConstraints { make in
            make.right.left.height.equalTo(scanView)
            make.top.equalTo(scanView.snp.bottom)
        }
        findView.snp.makeConstraints { make in
            make.right.left.height.equalTo(scanView)
            make.top.equalTo(weiChatView.snp.bottom)
        }
    }

    private lazy var scanView:MYGAddFriendHeaderCellView = {
        let v = MYGAddFriendHeaderCellView(icon: "friend_scan", titel: "我的二维码名片", content: "微信扫一扫添加为好友",frame: .zero)
        let tap = UITapGestureRecognizer(target: self, action: #selector(qrAddFriend))
        v.addGestureRecognizer(tap)
        return v
    }()
    
    private lazy var weiChatView:MYGAddFriendHeaderCellView = {
        let v = MYGAddFriendHeaderCellView(icon: "friend_weichat", titel: "微信好友", content: "去邀请微信好友",frame: .zero)
        return v
    }()
    
    private lazy var findView:MYGAddFriendHeaderCellView = {
        let v = MYGAddFriendHeaderCellView(icon: "friend_find", titel: "添加查找", content: "按条件查找陌生人",frame: .zero)
        let tap = UITapGestureRecognizer(target: self, action: #selector(searchAddFriend))
        v.addGestureRecognizer(tap)
        return v
    }()
    
    @objc func qrAddFriend() {
        let vc = MYGQRAddFriendVC()
        UIViewController.currentViewController?.navigationController?.pushViewController(vc)
    }
    
    @objc func searchAddFriend() {
        let vc = MYGFriendSearchViewController()
        UIViewController.currentViewController?.navigationController?.pushViewController(vc)
    }
    
    
    
}




class MYGAddFriendHeaderCellView: UIView {

    init(icon:String , titel:String, content:String,frame:CGRect) {
        super.init(frame: frame)
        configUI()
        Icon.image = UIImage(named: icon)
        nameLabel.text = titel
        contentLabel.text = content
        
       }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        backgroundColor = .rgba(250, 250, 250, 1)
        
        addSubview(Icon)
        addSubview(nameLabel)
        addSubview(contentLabel)
        addSubview(nextIcon)
        
        Icon.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(20)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(25)
        }
        nameLabel.snp.makeConstraints { make in
            make.left.equalTo(Icon.snp.right).offset(17.5)
            make.height.equalTo(22.5)
            make.top.equalTo(10)
        }
        contentLabel.snp.makeConstraints { make in
            make.left.equalTo(nameLabel)
            make.bottom.equalTo(nameLabel.snp.bottom).offset(15)
        }
        
        nextIcon.snp.makeConstraints { make in
            make.right.equalToSuperview().inset(8)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(12)
        }
        
    }
    
    private lazy var Icon:UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        return v
    }()
    
    private lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(16)
        label.textColor = .rgba(44, 44, 44, 1)
        return label
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(12)
        label.textColor = .rgba(128, 128, 128, 1)
        return label
    }()
    private lazy var nextIcon:UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "Find/right")
        v.contentMode = .scaleAspectFill
        return v
    }()
    
}
